package org.swqsbssddqs.shortlink.project.mq.producer;

import com.alibaba.fastjson2.JSON;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;
import org.swqsbssddqs.shortlink.project.dto.biz.ShortLinkStatsRecordDTO;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

import static org.swqsbssddqs.shortlink.project.common.constant.KafkaTopicConstant.STATS_SAVE_KAFKA_TOPIC;

@Component
@RequiredArgsConstructor
@Slf4j
public class KafkaShortLinkStatsSaveProducer {
//    private final KafkaTemplate<String, String> kafkaTemplate;
//
//
//    public void sendStatsSaveMessage(ShortLinkStatsRecordDTO msg) {
//        try {
//            send(STATS_SAVE_KAFKA_TOPIC, msg);
//        } catch (IOException ex) {
//            // 某某某情况宕机了
//            log.error("记录短链接监控消费异常", ex);
//            throw new RuntimeException(ex);
//        }
//    }
//
//    private void send(String topic, Object msg) throws IOException {
//        ProducerRecord<String, String> pr = new ProducerRecord<>(topic, JSON.toJSONString(msg));
//        pr.headers().add("type", msg.getClass().getName().getBytes(StandardCharsets.UTF_8));
//        kafkaTemplate.send(pr);
//    }
}
